
<!--
* description: 今日线索跟进
* author: mwh
* createdDate: 2010-11-21
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamicButtonsRight="tableButtonsRight"
      :dynamicButtons="tableButtons"
      :dynamicComponents="tableComponents"
      :dynamicApiConfig="apiConfig"
      :dynamicTableCols="tableCols"
      :dynamicFormFields="formField"
      :dynamicIsShowSelect="false"
      :dynamicIsInitTable="false"
      :dynamicIsColumnDrop="false"
      @changeToggleProp="changeToggleProp"
    />
    <!-- <edit
    :curPopupsVisible="editVisible"
    :editKey="editKey"
    ></edit> -->
  </div>

</template>
<script>
import { crmApis } from "@/api/apiList/crm.js";
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import OneTableTemplate from "@/components/crm/Template/crmonePage";
import Vue from "vue";

export default {
  name: "crmTodayPendingthread",
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],
  components: {
    OneTableTemplate,
    // edit:()=>import("./cluesAssignedTodayfollowUp.vue")
  },
  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData(to.path, function () {
      next();
    });
  },
  data() {
    let that = this;
    return {
      editVisible:true,
      editKey:"editKey",
      queryParam: "",
      placeHolder: `客户名称/电话`,
      // 网格查询API配置对象
      apiConfig: crmApis.clueServerQueryFromDlr,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "",
          size: "small",
          // clickEvent: () => this.exportExcel("本人当日待回访线索.xlsx", "本人当日待回访线索", ),
          clickEvent: () => this.export(),
          text: "导出",
        },
      ],
      tableButtonsRight: [
        {
          compKey: "btnKey10001",
          type: "",
          size: "small",
          icon: "el-icon-refresh",
          clickEvent: () => this.reset1(),
          text: "重置",
        },
        {
          compKey: "btnKey10000",
          type: "primary",
          icon: "el-icon-search",
          size: "small",
          clickEvent: () => this.query(),
          text: "查询",
        },
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
              .tableComponents
          : [
              {
                compKey: "compKey1",
                labelName: "客户名称",
                codeField: "custName",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: false,
              },
              {
                compKey: "compKey2",
                labelName: "电话",
                codeField: "contactTel",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: false,
              },
              {
                compKey: "compKey5",
                labelName: "线索单号",
                codeField: "serverOrder",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: false,
              },
              {
                compKey: "compKey3",
                labelName: "单据状态",
                codeField: "status",
                lookuptype: "LX181",

                component: () =>
                  import("@/components/crm/lookupValue/lookupvalue"),
                type: "dropdownList",
                isMust: false,
                isMul: false,
              },
              {
                compKey: "compKey4",
                labelName: "作业状态",
                codeField: "crruNode",
                lookuptype: "LX182",
                component: () => import("@/components/org/LookupValue"),
                type: "dropdownList",
                isMust: false,
                isMul: false,
              },
              {
                compKey: "compKey11",
                labelName: "首次回访",
                codeField: "isFirstCallback",
                lookuptype: "LX007",
                component: () => import("@/components/org/LookupValue"),
                type: "dropdownList",
                isMust: false,
                isMul: false,
              },
              {
                compKey: "compKey7",
                labelName: "意向品牌",
                codeField: "carBrandCode",
                textField: "carBrandCn",
                lookuptype: crmApis.mdmCarBrandQueryByPage,
                component: () =>
                  import("@/components/crm/lookupValue/apiDropList"),
                type: "dropdownList",
                isMust: false,
                isMul: false,
              },
              {
                compKey: "compKey6",
                labelName: "意向车系",
                codeField: "inteSeriesId",
                component: () =>
                  import(
                    "@/components/crm/crmEjectWindows/crmIntenCarSeries/index"
                  ),
                type: "propus",
                isMust: false,
                isMul: false,
                // emitCode: this.inteSeriesChange,
              },

              {
                compKey: "compKey8",
                labelName: "意向级别",
                codeField: "clueLevelCode",
                lookuptype: "LX141",
                attribute: "1",
                component: () =>
                  import("@/components/crm/lookupValue/lookupvalue"),
                type: "dropdownList",
                isMust: false,
                isMul: false,
              },
              {
                compKey: "compKey9",
                labelName: "线索渠道",
                codeField: "cantactWayCode",
                textField: "cantactWayName",
                lookuptype: crmApis.pcDbCantactWayQueryFindAll,
                component: () =>
                  import("@/components/crm/lookupValue/singleDropList"),
                type: "dropdownList",
                isMust: false,
                isMul: false,
                // changeCode: this.cantactWayChange,
              },
              {
                compKey: "cantactWayCode", //KEY标识
                labelName: "一级信息来源", //label标签名称
                codeField: "infoChanMCode", //label下拉框code
                textField: "infoChanMName", //label下拉框中文
                lookuptype: crmApis.pcDbInfoChanMQueryFind, //API或者值列表编码
                changeCodeArray: [{ changCode: "cantactWayCode" }],
                component: () =>
                  import("@/components/crm/lookupValue/secondDropList"), //导入的组件路径
                type: "dropdownList", //导入的组件类型
                isMust: false, //是否必填对应required
                isMul: false,
              },
              {
                compKey: "compKey13",
                labelName: "二级信息来源",
                codeField: "infoChanDName",
                component: () =>
                  import("@/components/crm/textbox/crmTextInput"),
                type: "",
                isMust: false,
              },
              // {
              //   compKey: "compKey8",
              //   labelName: "下次回访时间",
              //   codeField: "nextCallbackDateStart,nextCallbackDateEnd",
              //   // component: () => import("@/components/crm/Time/crmdtDatePicker"),
              //   component: () =>
              //     import("@/components/crm/Time/crmdtDatePicker_Now"),
              //   type: "inputText",
              //   isMust: false,
              //   disabled:true,
              // },

              {
                compKey: "compKey12",
                labelName: "建单时间",
                codeField: "createdDateStart,createdDateEnd",
                component: () =>
                  import("@/components/crm/Time/crmdtDatePicker"),
                type: "inputText",
                isMust: false,
              },
              {
                compKey: "compKey14",
                labelName: "留资时间",
                codeField: "remainDataDateStart,remainDataDateEnd",
                component: () =>
                  import("@/components/crm/Time/crmdtDatePicker"),
                type: "date",
                isRequire: false,
                isMust: false,
              },
            ],
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
              {
                prop: "controlBtn",
                label: "操作",
                width: 60,
                align: "center",
                codeField: "controlBtn",
                isComponent: true,
                fixed: true,
                comps: [
                  {
                    compKey: "propKey1",
                    labelName: "处理",
                    codeField: "editControlBtn",
                    align: "center",
                    isShowLabel: true,
                    isShow: true,
                    clickEvent: (index) => this.edit(index),
                    // clickEvent: this.edit,
                    component: () => import("@/components/org/linkButton"),
                  },
                ],
              },

              {
                prop: "custName",
                label: "客户名称",
                width: 100,
                align: "center",
                fixed: true,
              },
              {
                prop: "contactTel",
                label: "电话",
                width: 120,
                align: "center",
                fixed: true,
              },

              {
                prop: "serverOrder",
                label: "线索单号",
                width: 200,
                align: "center",
              },
              {
                prop: "statusName",
                label: "单据状态",
                width: 80,
                align: "center",
              },
              {
                prop: "crruNodeName",
                label: "作业状态",
                width: 80,
                align: "center",
              },
              {
                prop: "isFirstCallbackName",
                label: "首次回访",
                width: 80,
                align: "center",
              },
              {
                prop: "carBrandName",
                label: "意向品牌",
                width: 130,
                align: "center",
              },
              {
                prop: "carSeriesCn",
                label: "意向车系",
                width: 130,
                align: "center",
                // hidden:true
              },

              {
                prop: "clueLevelCode",
                label: "意向级别",
                width: 80,
                align: "center",
              },
              // {
              //   prop: "actionName",
              //   label: "活动名称",
              //   width: 100,
              //   align: "center"
              // },
              {
                prop: "cantactWayName",
                label: "线索渠道",
                width: 130,
                align: "center",
              },
              {
                prop: "infoChanMName",
                label: "一级信息来源",
                width: 130,
                align: "center",
              },
              {
                prop: "infoChanDName",
                label: "二级信息来源",
                width: 130,
                align: "center",
              },
              {
                prop: "createdDate",
                label: "建单时间",
                width: 150,
                align: "center",
                // hidden:true
              },
              {
                prop: "remainDataDate",
                label: "留资时间",
                width: 150,
                align: "center",
              },
              {
                prop: "nextCallbackDate",
                label: "下次回访时间",
                width: 150,
                align: "center",
              },
              {
                prop: "phoneForAttr",
                label: "号码归属地",
                width: 120,
                align: "center",
              },
              {
                prop: "processingAction",
                label: "",
                width: null,
                align: "center",
                hidden: true,
              },
            ],
      // 表单查询数据--重置查询条件
      formField: {
        // oemCode:"1",
        // groupCode: "1",
        custName: "",
        contactTel: "",
        serverOrder: "",
        createdDateStart: that.getStartDate() + " 00:00:00",
        createdDateEnd: that.getEndDate() + " 00:00:00",
        "createdDateStart,createdDateEnd": [
          that.getStartDate() + " 00:00:00",
          that.getEndDate() + " 00:00:00",
        ],

        cantactWayCode: "",
        infoChanMCode: "",
        isFirstCallback: "",
        nextCallbackDateStart: "",
        nextCallbackDateEnd: "",

        inteSeriesId: "",
        carBrandCode: "",
        clueLevelCode: "",
        status: "",
        infoChanDName: "",
        crruNode: "",
        remainDataDateStart: "",
        remainDataDateEnd: "",
        statusArray: ["10", "20", "21", "30", "31"],
        handleCode: "0", //[0：本人线索查询，1：本店线索查询]
        // searchValue:"",//搜素字段
        clueLevelArray: ["A", "B", "H"],
      },
    };
  },
  mounted() {},
  methods: {
    query() {
      let time1 = new Date().getFullYear();
      let time2 = new Date().getMonth() + 1;
      let time3 = new Date().getDate();
      if (time2 < 10) {
        time2 = "0" + time2;
      }
      if (time3 < 10) {
        time3 = "0" + time3;
      }
      this.formField.nextCallbackDateStart =
        time1 + "-" + time2 + "-" + time3 + " 00:00:00";
      this.formField.nextCallbackDateEnd =
        time1 + "-" + time2 + "-" + time3 + " 00:00:00";
      // this.queryTable(1);
      let obj = {};
      obj.formField = JSON.parse(JSON.stringify(this.formField));
      this.$delete(obj.formField, "createdDateStart,createdDateEnd");
      this.queryTable(1, null, null, null, null, obj);
    },
    reset1() {
      let that = this;
      this.formField["createdDateStart,createdDateEnd"] = [
        this.getStartDate() + " 00:00:00",
        this.getEndDate() + " 00:00:00",
      ];
      let patt = new RegExp(",");
      for (let key in that.$refs.multipleTable.$refs) {
        if (
          that.$refs.multipleTable.$refs[key][0] &&
          that.$refs.multipleTable.$refs[key][0].codeField
        ) {
          let flag = patt.test(
            that.$refs.multipleTable.$refs[key][0].codeField
          );
          if (flag) {
            that.$refs.multipleTable.$refs[key][0].modelCode = [];
          }
        }
      }
      this.reset();
    },
    getStartDate() {
      let dd = new Date();
      dd.setMonth(dd.getMonth() - 1);
      let y = dd.getFullYear();
      let m = dd.getMonth() + 1;
      let d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
      return y + "-" + (m < 10 ? "0" + m : m) + "-" + d;
    },
    getEndDate() {
      let dd = new Date();
      let y = dd.getFullYear();
      let m = dd.getMonth() + 1;
      let d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
      return y + "-" + (m < 10 ? "0" + m : m) + "-" + d;
    },
    changeToggleProp() {
      this.reset1();
    },
    export() {
      let time1 = new Date().getFullYear();
      let time2 = new Date().getMonth() + 1;
      let time3 = new Date().getDate();
      if (time2 < 10) {
        time2 = "0" + time2;
      }
      if (time3 < 10) {
        time3 = "0" + time3;
      }
      this.formField.nextCallbackDateStart =
        time1 + "-" + time2 + "-" + time3 + " 00:00:00";
      this.formField.nextCallbackDateEnd =
        time1 + "-" + time2 + "-" + time3 + " 00:00:00";
      let obj = {};
      obj.formField = JSON.parse(JSON.stringify(this.formField));
      this.$delete(obj.formField, "createdDateStart,createdDateEnd");
      this.exportExcel(
        "本人当日待回访线索.xlsx",
        "本人当日待回访线索",
        -1,
        obj
      );
    },
    // inteSeriesChange(row) {
    //   this.formField.inteSeriesId = row[0].carSeriesId;
    // },
    //处理
    edit(index) {
      //that.$router.push({ name: "", params: row });
      this.$crmcf.jumpDetailTag(
        this,
        "crmThreadReturn",
        "/crmThreadReturn",
        this.$refs.multipleTable.list[index]
      );
    },
    //线索渠道change
    // cantactWayChange() {
    //   this.formField.infoChanMCode = "";
    // },
  },
};
</script>
